import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart' hide Action;
import 'package:www.znpigai.teacher/utils/nav.dart';
import 'package:www.znpigai.teacher/utils/util.dart';

import 'action.dart';
import 'state.dart';

Effect<HomeworkAnswerState> buildEffect() {
  return combineEffects(<Object, Effect<HomeworkAnswerState>>{
    HomeworkAnswerAction.onClick: _onClick,
  });
}

void _onClick(Action action, Context<HomeworkAnswerState> ctx) async {
//  Navigator.of(ctx.context).pushNamed(Nav.ANSWER_MARK, arguments: ctx.state);
//  return;
  switch (ctx.state.statuscn) {
    case '未提交':
      Util.alert('未提交，无法查看详情', ctx.context);
      break;
    case '已提交':
    case '待批阅':
      Navigator.of(ctx.context)
          .pushNamed(Nav.ANSWER_MARK, arguments: ctx.state);
      break;
    default:
      Navigator.of(ctx.context).pushNamed(Nav.WEB_PAGE, arguments: {
        'url':
            '/correct/pub/view/machine/review.mvc?id=${ctx.state.id}&ishomework=1',
        'share': false,
        'done': ''
      });
  }
}
